//
// Manager.cs
//
// Copyright (C) 2008 Lukas Lipka <lukaslipka@gmail.com>
//

using System;
using System.Reflection;
using System.Collections;

using NDesk.DBus;

namespace NetworkManager
{
	public enum State : uint {
		Unknown = 0,
		Asleep,
		Connecting,
		Connected,
		Disconnected
	}

	public struct NetworkConnection {
		string ServiceName;
		ObjectPath Connection;
		ObjectPath SpecificObject;
		ObjectPath[] DevicePath;
	}

	public class Manager : IEnumerable {

		private static readonly string PATH_NAME = "/org/freedesktop/NetworkManager";
		private static readonly string INTERFACE_NAME = "org.freedesktop.NetworkManager";

		private IManager manager = null;
		
		public Manager()
		{
			Bus bus = Bus.System;
			this.manager = bus.GetObject<IManager> (INTERFACE_NAME, new ObjectPath (PATH_NAME));
		}

		public void Sleep (bool sleep)
		{
			manager.Sleep (sleep);
		}
                      
		public IEnumerator GetEnumerator()
		{
			foreach (ObjectPath op in manager.GetDevices ()) {
				yield return new Device (op);
			}
		}
		
		public State State {
			get { return manager.State; }
		}
        
		public bool WirelessEnabled {
			get { return manager.WirelessEnabled; }
		}
        }
}
